package jbox2dprocessing.compontent;

import processing.core.PApplet;
import processing.core.PConstants;

public class Buttons {
	
	public static PApplet parent;
	
	public static int MOUSEOVER = 0;
	public static int MOUSECLICK = 1;
	public static int MOUSEPRESSED = 2;
	public static int MOUSERELEASED = 3;
	
	public float buttonX;
	public float buttonY;
	public float buttonWidth;
	public float buttonHeight;
	
	public int buttonColor;
	public int buttonStrokeColor;
	public int buttonStrokeWeight;
	public int defaultButtonColor = parent.color(244);
	public int defaultButtonStrokeColor = parent.color(111);
	public int hoverButtonsStrokeColor = parent.color(0,255,0);
	public int defaultButtonStrokeWeight = 2;
	
	
	//	0 -- Creation Shape;  1 -- Move Shape
	public int buttonType;
	
	public Buttons(float buttonX, float buttonY, int buttonColor, int buttonType) {
		super();
		this.buttonX = buttonX;
		this.buttonY = buttonY;
		this.buttonWidth = 100;
		this.buttonHeight = 40;
		this.buttonColor = buttonColor;
		this.buttonStrokeColor = defaultButtonStrokeColor;
		this.buttonStrokeWeight = defaultButtonStrokeWeight;
		
		this.buttonType = buttonType;
		
		display();
	}

	public Buttons(float buttonX, float buttonY, float buttonWidth,
			float buttonHeight, int buttonColor, int buttonStrokeColor,
			int buttonStrokeWeight, int buttonType) {
		super();
		this.buttonX = buttonX;
		this.buttonY = buttonY;
		this.buttonWidth = buttonWidth;
		this.buttonHeight = buttonHeight;
		this.buttonColor = buttonColor;
		this.buttonStrokeColor = buttonStrokeColor;
		this.buttonStrokeWeight = buttonStrokeWeight;
		
		this.buttonType = buttonType;
		
		display();
	}

	public void display() {
		parent.rectMode(PConstants.CORNER);
		parent.fill(buttonColor);
		parent.stroke(buttonStrokeColor);
		parent.strokeWeight(buttonStrokeWeight);
		parent.rect(buttonX, buttonY, buttonWidth, buttonHeight);
	}
	
	public boolean buttonEventListener(int eventType,  float x, float y){
		if(eventType == MOUSEOVER){
			if(x>buttonX && x<buttonX+buttonWidth && y>buttonY && y<buttonY+buttonHeight){
				buttonStrokeColor = hoverButtonsStrokeColor;
				return true;
			}
			else{
				buttonStrokeColor = defaultButtonStrokeColor;
				return false;
			}
		}
		else{
			return false;
		}
	}
}











